/* 
 * Copyright (c) 2012, Fromentin Xavier, Schnell Michaël, Dervin Cyrielle, Brabant Quentin
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *      * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *      * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *      * The names of its contributors may not be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL Fromentin Xavier, Schnell Michaël, Dervin Cyrielle OR Brabant Quentin 
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
package kameleon.gui.model;

import java.io.File;
import java.io.Serializable;
import java.util.Date;

/**
 * Used to store the informations about the files in the history.
 * 
 * @author		Dervin Cyrielle, Fromentin Xavier
 * @version		1.0
 */
public class FileInfo implements Serializable {

	/**
	 * Needed to serialize this class.
	 * 
	 * @see		java.io.Serializable
	 */
	private static final long serialVersionUID = 4161712822519450295L;

	/**
	 * Absolute path of the file attached to this instance.
	 */
	private String path ;

	/**
	 * Name of the file attached to this instance.
	 */
	private String name ;

	/**
	 * Id of the analyzer used to analyze the file attached to this instance.
	 */
	private String idFormat ;

	/**
	 * Last generation date.
	 */
	private Date lastGeneration ;

	/**
	 * Ids of the generators used during the last generation.
	 */
	private String[] targetGeneratorIds ;

	/**
	 * Absolute paths of the last generated files.
	 */
	private String[] targetPaths ;

	/**
	 * Creates a new instance of {@code FileInfo} with the given path.
	 * 
	 * @param	path
	 * 			path of the file attached to this instance
	 */
	public FileInfo(String path) {
		this.path = path ;
		this.name = new File(path).getName() ;
		this.idFormat = null ;
		this.lastGeneration = null ;
		this.targetGeneratorIds = null ;
		this.targetPaths = null ;
	}// FileInfo(String)

	/**
	 * Returns the absolute path of the file attached to this instance.
	 * 
	 * @return	Absolute path of the file attached to this instance
	 */
	public String getPath() {
		return this.path ;
	}// getPath()

	/**
	 * Sets the absolute path of the file attached to this instance.
	 * 
	 * @param	path
	 * 			absolute path of the file
	 */
	public void setPath(String path) {
		this.path = path ;
		if (this.path != null) {
			this.name = new File(this.path).getName() ;
		}// if
	}// setPath(String)


	/**
	 * Returns the name of the file attached to this instance.
	 * 
	 * @return	Name of the file attached to this instance
	 */
	public String getName() {
		return this.name ;
	}// getName()

	/**
	 * Returns the id of the analyzer used to analyze the file.
	 * 
	 * @return	Id of the analyzer used to analyze the file
	 */
	public String getIdFormat() {
		return this.idFormat ;
	}// getIdFormat()

	/**
	 * Sets the id of the analyzer used to analyze the file.
	 * 
	 * @param	idFormat
	 * 			id of the analyzer
	 */
	public void setIdFormat(String idFormat) {
		this.idFormat = idFormat ;
	}// setIdFormat(String)

	/**
	 * Returns the last generation date.
	 * 
	 * @return	Last generation date or {@code null} if 
	 * 			the file was never generated
	 */
	public Date getLastGeneration() {
		return this.lastGeneration ;
	}// getLastGeneration()

	/**
	 * Sets the last generation date.
	 * 
	 * @param	lastGeneration
	 * 			date of the last generation
	 */
	public void setLastGeneration(Date lastGeneration) {
		this.lastGeneration = lastGeneration;
	}// setLastGeneration(Date)

	/**
	 * Returns the ids of the generators used for the last generation.
	 * 
	 * @return	array containing the ids of the used generators or 
	 * 			{@code null} if the file was never generated
	 */
	public String[] getTargetFormatId() {
		return this.targetGeneratorIds;
	}// getTargetFormatId()

	/**
	 * Sets the ids of the generators used for the last generation.
	 * 
	 * @param	targetFormatIds
	 * 			array containing the ids of the used generators
	 */
	public void setTargetFormatId(String[] targetFormatIds) {
		this.targetGeneratorIds = targetFormatIds ;
	}// setTargetFormatId(String[])

	/**
	 * Returns the absolute paths of the generated files.
	 * 
	 * @return	Array containing the absolute paths or 
	 * 			{@code null} if the file was never generated
	 */
	public String[] getTargetPath() {
		return this.targetPaths ;
	}// getTargetPath()

	/**
	 * Sets the absolute paths of the generated files.
	 * 
	 * @param 	targetPaths 
	 * 			Array containing the absolute paths
	 */
	public void setTargetPaths(String[] targetPaths) {
		this.targetPaths = targetPaths ;
	}// setTargetPaths(String[])

	/**
	 * Indicates whether two objects are "equal". Two instances
	 * of {@code FileInfo} are considered "equal" if their
	 * file paths are the same.
	 * 
	 * @param	obj
	 * 			object compared to this
	 * 
	 * @return	{@code true} if {@code (obj instanceof FileInfo)
	 * 			&& this.getPath().equals(obj.getPath())}, 
	 * 			{@code false} otherwise
	 */
	@Override
	public boolean equals(Object obj) {
		if ((obj == null) || !(obj instanceof FileInfo)) {
			return false ;
		}// if
		FileInfo other = (FileInfo) obj ;
		return this.path.equals(other.path) ;
	}// equals(Object)
	
	/**
	 * {@inheritDoc}
	 */
	@Override
	public int hashCode() {
		return this.path.hashCode() ;
	}// hashCode()
	
}// class FileInfo